# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  # Pick a unique cookie name to distinguish our session data from others'
  #include AuthenticatedSystem

  # before_filter :login_from_cookie

  # before_filter :login_required

  session :session_key => '_ocm_session_id'

  # Filter out the password from the logs.
  filter_parameter_logging "password"

  before_filter do |c|
    if !c.session[:user].nil?
      User.current_user = c.session[:user]
    end
  end

  def login_required
    if session[:user]
      return true
    end
    flash[:warning] = "Please login to continue."
    session[:return_to] = request.request_uri
    redirect_to :controller => "account", :action => "login"
    return false
  end

  def current_user
    session[:user]
  end

  def redirect_to_stored
    if return_to = session[:return_to]
      session[:return_to] = nil
      redirect_to_url(return_to)
    else
      redirect_to :controller => "user", :action => "welcome"
    end
  end
end
